package com.example.demo.service;

import com.example.demo.dao.SupplierJPARepository;
import com.example.demo.entity.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierService {
    @Autowired
    SupplierJPARepository supplierRepository;

    public Supplier addSupplier(Supplier supplier) {
       return supplierRepository.saveAndFlush(supplier);
    }
    public Supplier getSupplier(long id){
        return supplierRepository.getById(id);
    }
    public void deleteSupplier(long id){
        supplierRepository.deleteById(id);
    }
    public void updateSupplier(long id,Supplier supplier){
        supplierRepository.save(supplier);
    }
    public List<Supplier> findSupplierByName(String name){
        return supplierRepository.findByName(name);
    }
}
